﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Threading;
using System.ComponentModel;

namespace OnTheWay.Functions
{
    [DesignTimeVisible(false)]
    public class FunctionCtrlWait : FunctionCtrlCmd
    {

        #region 等待信息数据
        /// <summary>
        /// 等待页面显示开关
        /// </summary>
        public Visibility WaitVisibility
        {
            get { return (Visibility)GetValue(WaitVisibilityProperty); }
            set { SetValue(WaitVisibilityProperty, value); }
        }

        // Using a DependencyProperty as the backing store for WaitVisibility.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty WaitVisibilityProperty =
            DependencyProperty.Register("WaitVisibility", typeof(Visibility), 
            typeof(FunctionCtrlWait),
            new UIPropertyMetadata(Visibility.Collapsed));

        /// <summary>
        /// 等待页面显示信息
        /// </summary>
        public string WaitMessage
        {
            get { return (string)GetValue(WaitMessageProperty); }
            set { SetValue(WaitMessageProperty, value); }
        }

        // Using a DependencyProperty as the backing store for WaitMessage.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty WaitMessageProperty =
            DependencyProperty.Register("WaitMessage", typeof(string), 
            typeof(FunctionCtrlWait), new UIPropertyMetadata("正在加载数据..."));

        #endregion

        #region 异步信息数据

        /// <summary>
        /// 等待页面显示开关
        /// </summary>
        public Visibility DispatchWaitVisibility
        {
            set 
            {
                this.Dispatcher.Invoke(new Action(() => 
                {
                    WaitVisibility = value;
                }));
            }
        }

        /// <summary>
        /// 等待页面显示信息
        /// </summary>
        public string DispatchWaitMessage
        {
            set
            {
                this.Dispatcher.Invoke(new Action(() =>
                {
                    WaitMessage = value;
                }));
            }
        }

        #endregion

        #region 命令实现

        //protected override bool OnCanCommandRefresh(object obj)
        //{
        //    return (this.WaitVisibility != Visibility.Visible);
        //}

        //protected override bool OnCanCommandAdd(object obj)
        //{
        //    return WaitVisibility != Visibility.Visible;
        //}

        //protected override bool OnCanCommandDelete(object obj)
        //{
        //    return WaitVisibility != Visibility.Visible;
        //}

        //protected override bool OnCanCommandModify(object obj)
        //{
        //    return WaitVisibility != Visibility.Visible;
        //}

        //protected override bool OnCanCommandSelect(object obj)
        //{
        //    return WaitVisibility != Visibility.Visible;
        //}

        //protected override bool OnCanCommandSave(object obj)
        //{
        //    return WaitVisibility != Visibility.Visible;
        //}

        //protected override bool OnCanCommandClose(object obj)
        //{
        //    return WaitVisibility != Visibility.Visible;
        //}

        #endregion
    }
}
